package org.grottarossa.domain;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.FetchGroup;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Key;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Serialized;
import javax.jdo.annotations.Value;

import org.grottarossa.domain.Field;
import org.grottarossa.query.docs.CaseFolderSolrDoc;
import org.grottarossa.query.docs.SolrMainObject;
import org.springframework.beans.BeanUtils;

@PersistenceCapable(identityType = IdentityType.DATASTORE, detachable = "true")
@FetchGroup(name = "caseF", members = { @Persistent(name = "fields") })
public class CaseFolder extends CaseFolderSolrDoc
{	
	@PrimaryKey 
	@Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT)
	@Serialized
	private String id;

	@Persistent
	private long createTime = System.currentTimeMillis();

	@Persistent
	private String name;

	@Persistent
	private String description;

	@Element(embedded="false") 
	@Key(types=String.class) @Value(types=String.class)
	private Record record;
	
	//@Element(embedded="false")
	//@Key(types=String.class) @Value(types=String.class)
	private Collection<Task> tasks;
	
	//miss document
	//miss ACL
	//miss history
	//miss discussion
		
	public Record getRecord() {
		return record;
	}

	public void setRecord(Record record) {
		this.record = record;
	}

	public void setTasks(Collection<Task> tasks) {
		this.tasks = tasks;
	}

	public CaseFolder() 
	{
		this.tasks = new HashSet<Task>(0);		
	}
		
	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}
		
	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "name:" + name + " description:" + description + "\nfield"
				+ record.toString();
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param fields
	 *            the fields to set
	 */
	

	/**
	 * @param tasks
	 *            the tasks to set
	 */
	public void setTasks(Set<Task> tasks) {
		this.tasks = tasks;
	}

	/**
	 * @return the tasks
	 */
	public Collection<Task> getTasks() {
		return tasks;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}
	
	public void setId(String id)
	{
		this.id = id;
	}
	
	@Override
	public int hashCode() 
	{
		return Integer.parseInt(this.id);
	}

	@Override
	public boolean equals(Object obj) 
	{		
		return compare(obj);
	}

	@Override
	public void update(Object casefolder) 
	{
		BeanUtils.copyProperties(casefolder, this, CaseFolder.class);		
	}

	@Override	
	public Object cloneObj() 
	{			
		return cloneObj(CaseFolder.class);
	}
}
